package com.ke.jdyd.http;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class HttpParamHelper {
  /**
   * 转换为 form-data
   */
  public static Map<String, RequestBody> generateRequestBody(Map<String, String> requestDataMap) {
    Map<String, RequestBody> requestBodyMap = new HashMap<>();
    for (String key : requestDataMap.keySet()) {
      RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"),
          requestDataMap.get(key) == null ? "" : requestDataMap.get(key));
      requestBodyMap.put(key, requestBody);
    }
    return requestBodyMap;

  }
  public static RequestBody getJSONParams(Map<String, String> params) {
    return RequestBody.create(MediaType.parse("application/json"),
        new JSONObject(params).toString());
  }
}
